#include "OriginPCH.h"

#include "Core/Log.h"
#include "OpenGLContext.h"
#include <glad/glad.h>
#include <GLFW/glfw3.h>


namespace Origin
{
    OpenGLContext::OpenGLContext(GLFWwindow* windowHandle): _windowHandle(windowHandle)
    {
        ORIGIN_CORE_ASSERT(windowHandle, "Window handle is null!");
    }

    void OpenGLContext::Init()
    {
        glfwMakeContextCurrent(_windowHandle);
        int status = gladLoadGLLoader((GLADloadproc)glfwGetProcAddress);
        ORIGIN_CORE_ASSERT(status, "Failed to initialize Glad!");

        ORIGIN_CORE_INFO("OpenGL Info:");
        ORIGIN_CORE_INFO("  Vendor: {0}", *glGetString(GL_VENDOR));
        ORIGIN_CORE_INFO("  Renderer: {0}", *glGetString(GL_RENDERER));
        ORIGIN_CORE_INFO("  Version: {0}", *glGetString(GL_VERSION));
    }

    void OpenGLContext::SwapBuffers()
    {
        glfwSwapBuffers(_windowHandle);
    }

}